use std::collections::HashMap;
use trait_demo_demo::{Point, newlargest};

fn main() {
    let mut scores = HashMap::new();

    scores.insert(String::from("Blue"), 10);
    scores.insert(String::from("Yellow"), 50);
    scores.entry(String::from("Blues")).or_insert(50);

    for (key, value) in &scores {
        println!("{}: {}", key, value);
    }

    let mut ss = HashMap::new();
    ss.insert(String::from("guge"), 10);
    ss.insert(String::from("guges"), 10);
    for (key, value) in &ss {
        println!("{}: {}", key, value);
    }


    let text = "hello world wonderful world";

    let mut map = HashMap::new();

    for word in text.split_whitespace() {
        let count = map.entry(word).or_insert(0);
        *count += 1;
    }

    println!("{:?}", map);


    let number_list = vec![34, 50, 25, 100, 65];
    let num_some = vec![2, 8, 9, 6, 5];

    let mut largest = number_list[0];

    for number in number_list {
        if number > largest {
            largest = number;
        }
    }

    println!("{:?}", largest);

    let num = sycnc(&num_some);

    println!(" num   {:?}", num);


    //-------------------

    let p1 = Point { x: 5, y: 10.4 };
    let p2 = Point { x: "Hello", y: 'c' };
    let p3 = p1.mixup(p2);

    println!("p3.x = {}, p3.y = {}", p3.x, p3.y);


//    -----------------------------------------
    let number_list = vec![34, 50, 25, 100, 65];
    let result = newlargest(&number_list);
    println!("The largest number is ----- {}", result);

    let string1 = String::from("long string is long");

    {
        let string2 = String::from("xyz");
        let result = longest(string1.as_str(), string2.as_str());
        println!("The longest string is {}", result);
    }


}




fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
    if x.len() > y.len() {
        x
    } else {
        y
    }
}


fn sycnc(list: &[i32]) -> i32 {
    let mut largest = list[0];

    for &item in list.iter() {
        if item > largest {
            largest = item;
        }
    }

    largest
}